<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <body>
            <f:view>
                <p:dialog id="dialog" header="Login" widgetVar="dlg" rendered="true" visible="true" appendToBody="true">  
                    <h:form>  

                        <h:panelGrid columns="2" cellpadding="5">  
                            <h:outputLabel for="username" value="Username: *" />  
                            <p:inputText value="#{loginBacking.name}"   
                                         id="username" required="true" label="username" />  

                            <h:outputLabel for="password" value="Password: * " />  
                            <h:inputSecret value="#{loginBacking.password}"   
                                           id="password" required="true" label="password" />  

                            <f:facet name="footer">  
                                <p:commandButton value="Login" update="growl"   
                                                 actionListener="#{loginBacking.login}"   
                                                 oncomplete="handleLoginRequest(xhr, status, args)"/>  
                            </f:facet>  
                        </h:panelGrid>  

                    </h:form>  
                </p:dialog>

                <c:if test="#{! empty flash.expiredViewId}">
                    <p>To protect your security, your session has expired.  The page you were
                        last looked at was #{flash.expiredViewId}.</p>
                </c:if>

           
            
            <script type="text/javascript">  
            function handleLoginRequest(xhr, status, args) {  
                if(args.validationFailed || !args.loggedIn) {  
                    jQuery('#dialog').parent().effect("shake", { times:3 }, 100);  
                } else {  
                    dlg.hide();  
                    jQuery('#loginLink').fadeOut(); 
                    document.location.href='/index.xhtml';
                }  
            }
             jQuery(function() {
             dlg.show();  
           });
            </script>
           </f:view>
    </body>
</html>
